<!--
 ~ Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 ~
 ~ WSO2 Inc. licenses this file to you under the Apache License,
 ~ Version 2.0 (the "License"); you may not use this file except
 ~ in compliance with the License.
 ~ You may obtain a copy of the License at
 ~
 ~    http://www.apache.org/licenses/LICENSE-2.0
 ~
 ~ Unless required by applicable law or agreed to in writing,
 ~ software distributed under the License is distributed on an
 ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 ~ KIND, either express or implied.  See the License for the
 ~ specific language governing permissions and limitations
 ~ under the License.
 -->
<pre style="line-height: 100%;font-family:monospace;background-color:#ffffff; border-width:0.01mm; border-color:#000000; border-style:solid;padding:4px;font-size:10pt;"><span style="background-color:#edffed;">&lt;%@ page import="org.wso2.carbon.context.CarbonContext" %&gt;

&lt;h2&gt;WSO2 Carbon Caching Demo&lt;/h2&gt;

&lt;hr/&gt;
&lt;p&gt;

&lt;h3&gt;Add to Cache&lt;/h3&gt;

&lt;form action="index.jsp" method="POST"&gt;
    &lt;table border="0"&gt;
        &lt;tr&gt;
            &lt;td&gt;Key&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="key"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;Value&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="value"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&nbsp;&lt;/td&gt;
            &lt;td&gt;&lt;input type="submit" value="Add" name="add"&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
&lt;/form&gt;
&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;

&lt;h3&gt;Read from Cache&lt;/h3&gt;

&lt;form action="index.jsp" method="POST"&gt;
    &lt;table border="0"&gt;
        &lt;tr&gt;
            &lt;td&gt;Key&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="key"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&nbsp;&lt;/td&gt;
            &lt;td&gt;&lt;input type="submit" value="View" name="view"&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
&lt;/form&gt;
&lt;/p&gt;
&lt;hr/&gt;

</span><span style="color:#000080;background-color:#fffce4;">&lt;%
</span><span style="background-color:#edffed;">    // The CarbonContext instance used to obtain the cache
    CarbonContext cCtx = CarbonContext.getCurrentContext();

    if (request.getParameter("add") != null) {
        String key = request.getParameter("key");
        cCtx.getCache().put(key, request.getParameter("value"));
</span><span style="color:#000080;background-color:#fffce4;">%&gt;
</span><span style="background-color:#edffed;">&lt;p&gt;
    Added entry: </span><span style="color:#000080;background-color:#fffce4;">&lt;%=</span><span style="background-color:#edffed;"> key </span><span style="color:#000080;background-color:#fffce4;">%&gt;
</span><span style="background-color:#edffed;">&lt;/p&gt;
</span><span style="color:#000080;background-color:#fffce4;">&lt;%
</span><span style="background-color:#edffed;">    } else if (request.getParameter("view") != null) {
        String key = request.getParameter("key");
        if (cCtx.getCache().get(key) != null) {
            String content = (String)cCtx.getCache().get(key);
</span><span style="color:#000080;background-color:#fffce4;">%&gt;
</span><span style="background-color:#edffed;">            &lt;p&gt;
                Value of entry </span><span style="color:#000080;background-color:#fffce4;">&lt;%=</span><span style="background-color:#edffed;"> key</span><span style="color:#000080;background-color:#fffce4;">%&gt;</span><span style="background-color:#edffed;"> : </span><span style="color:#000080;background-color:#fffce4;">&lt;%=</span><span style="background-color:#edffed;"> content </span><span style="color:#000080;background-color:#fffce4;">%&gt;
</span><span style="background-color:#edffed;">            &lt;/p&gt;
</span><span style="color:#000080;background-color:#fffce4;">&lt;%
</span><span style="background-color:#edffed;">        } else {
</span><span style="color:#000080;background-color:#fffce4;">%&gt;
</span><span style="background-color:#edffed;">            &lt;p&gt;
                Unable to find an entry by the given key </span><span style="color:#000080;background-color:#fffce4;">&lt;%=</span><span style="background-color:#edffed;"> key</span><span style="color:#000080;background-color:#fffce4;">%&gt;</span><span style="background-color:#edffed;">!
            &lt;/p&gt;
</span><span style="color:#000080;background-color:#fffce4;">&lt;%
</span><span style="background-color:#edffed;">        }
    }
</span><span style="color:#000080;background-color:#fffce4;">%&gt;</span></pre>
